#include "emenyManager.h"
#include "selfBulletManager.h"
#include "burstManager.h"
#include "burst.h"
#include "selfBoneManager.h"

emenyManager* emenyManager::_instance = 0;

emenyManager* emenyManager::Instance()
{
	if (_instance == NULL)
	{
		_instance = new emenyManager();
	}
	return _instance;
}

emenyManager::emenyManager()
{
	sumNum = 0;
	for (int i = 0; i < 100; i++)
	{
		freeMem.push_back(new Emeny());
	}
	//manager.resize(100);
}

void emenyManager::draw()
{
	for (list<Emeny*>::iterator itor = manager.begin();
		itor != manager.end(); itor++)
	{
		(*itor)->draw();
	}
}

void emenyManager::updata()
{
	for (list<Emeny*>::iterator itor = manager.begin();
		itor != manager.end();)
	{
		if ((*itor)->checkRemove())
		{
			list<Emeny*>::iterator itor1 = itor;
			itor1++;
			freeMem.splice(freeMem.begin(), manager, itor);
			itor = itor1;
		}
		else
		{
			(*itor)->updata();
			itor++;
		}
	}
	//cout << freeMem.size() << " " << manager.size() << endl;
}

/*
void emenyManager::add(Emeny* e)
{
	manager.push_back(e);
}*/

void emenyManager::add(stdEmeny std, Point p, Point* play)
{
	list<Emeny*>::iterator itor = freeMem.begin();
	(*itor)->setinformation(std, p, play);
	manager.splice(manager.begin(), freeMem, itor);
}

void emenyManager::clear()
{
	freeMem.splice(freeMem.begin(), manager);
}

void emenyManager::checkHitPlayer(Player& p)
{
	for (list<Emeny*>::iterator itor = manager.begin();
		itor != manager.end(); itor++)
	{
		p.checkHit((*itor)->getNowPoint(), (*itor)->getRange());
	}
}

void emenyManager::checkHitBullet()
{
	selfBulletManager* m = 0;
	m = m->Instance();
	for (list<Emeny*>::iterator itor = manager.begin();
		itor != manager.end(); itor++)
	{
		for (list<selfBullet*>::iterator itor1 = m->manager.begin();
			itor1 != m->manager.end(); itor1++)
		{
			(*itor)->checkHit(**itor1);
		}
	}
	m = 0;
	
	selfBoneManager* m1 = 0;
	m1 = m1->Instance();
	for (list<Emeny*>::iterator itor = manager.begin();
		itor != manager.end(); itor++)
	{
		for (list<Bullet*>::iterator itor1 = m1->manager.begin();
			itor1 != m1->manager.end(); itor1++)
		{
			(*itor1)->checkHit(**itor);
		}
	}
	m1 = 0;
}